#pragma once
//============================================================================
// Copyright (C) 2011-2013 Brett R. Jones
// All Rights Reserved
//
// You may redistribute and/or modify for non commercial and commercial uses
// provided this copyright notice remains in place and is not modified
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================

#include <VxUtilLib/VxCommon.h>

#ifdef USE_PLUGIN_FILE_SERVER

#include <VxUtilLib/VxThread.h>
#include <VxUtilLib/VxMutex.h>
#include <RcPluginLib/RcPluginFileXBase.h>

class SharedDirInfo;

class SharedFilesMgr : public VxThread, public RcPluginFileXBase
{
public:
	//=== vars ===//
	S64								m_s64TotalByteCnt;
	U16								m_u16FileTypes;
	VxMutex							m_oFilesListMutex;

	std::vector<SharedDirInfo*>		m_oSharedList;
	

	//=== constructor ===//
	SharedFilesMgr();
	//=== destructor ===//
	virtual ~SharedFilesMgr();

	virtual void		onSharedFilesUpdated( void ){};

	//=== methods ===//
	void				sharedFilesUpdate( std::vector<std::string>& sharedDirList );

	/*
	void				addSharedDirectory( const char * pDirectory );
	void				removeSharedDirectory( const char * pDirectory );
*/

	void				updateFilesList( void );

	// should be private but is called from thread
	void				updateSharedDirectory( std::string& strDirectory );

	virtual bool		localFileNameToRemoteFileName( std::string& strLocalFileName, std::string& strRetRemoteFileName );
	virtual bool		remoteFileNameToLocalFileName( std::string& strRemoteFileName, std::string& strRetLocalFileName );
	void				updateFileTypes( void );

private:
	void				sharedFilesStartup();
	void				sharedFilesShutdown( void );

	void				clearSharedDirList( void );
};

#endif // USE_PLUGIN_FILE_SERVER